package com.xqboss.web.controller.nft;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.xqboss.apps.domain.nft.NftPublisher;
import com.xqboss.apps.service.nft.NftPublisherService;
import com.xqboss.common.annotation.Log;
import com.xqboss.common.core.controller.BaseController;
import com.xqboss.common.core.domain.AjaxResult;
import com.xqboss.common.core.domain.R;
import com.xqboss.common.core.page.TableDataInfo;
import com.xqboss.common.enums.BusinessType;
import com.xqboss.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Administrator
 */
@Api(tags = {"发行方管理"})
@RestController
@RequestMapping("/web/publisher")
public class WebNftPublisherController extends BaseController {
    @Autowired
    private NftPublisherService nftPublisherService;

    /**
     * 查询发行方列表
     */
    @PreAuthorize("@ss.hasPermi('web:publisher:list-page')")
    @ApiOperation("发行方列表")
    @GetMapping("/list-page")
    public R<List<NftPublisher>> list(NftPublisher nftPublisher) {
        if (ObjUtil.isNotNull(nftPublisher) && StrUtil.isNotBlank(nftPublisher.getKeyword())) {
            nftPublisher.setName(nftPublisher.getKeyword());
        }
        startPage();
        List<NftPublisher> list = nftPublisherService.selectNftPublisherList(nftPublisher);
        return R.ok(list);
    }

    /**
     * 导出发行方列表
     */
    @PreAuthorize("@ss.hasPermi('web:publisher:export')")
    @Log(title = "发行方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NftPublisher nftPublisher) {
        List<NftPublisher> list = nftPublisherService.selectNftPublisherList(nftPublisher);
        ExcelUtil<NftPublisher> util = new ExcelUtil<NftPublisher>(NftPublisher.class);
        util.exportExcel(response, list, "发行方数据");
    }

    /**
     * 获取发行方详细信息
     */
    @PreAuthorize("@ss.hasPermi('web:publisher:get')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(nftPublisherService.selectNftPublisherById(id));
    }

    /**
     * 新增发行方
     */
    @PreAuthorize("@ss.hasPermi('web:publisher:add')")
    @Log(title = "发行方", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody NftPublisher nftPublisher) {
        return toAjax(nftPublisherService.insertNftPublisher(nftPublisher));
    }

    /**
     * 修改发行方
     */
    @PreAuthorize("@ss.hasPermi('web:publisher:edit')")
    @Log(title = "发行方", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody NftPublisher nftPublisher) {
        return toAjax(nftPublisherService.updateNftPublisher(nftPublisher));
    }

    /**
     * 删除发行方
     */
    @PreAuthorize("@ss.hasPermi('web:publisher:delete')")
    @Log(title = "发行方", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(nftPublisherService.deleteNftPublisherByIds(ids));
    }
}
